$(function () {
    var World = Backbone.Model.extend({name: null});
    var Worlds = Backbone.Collection.extend({
        initialize: function (models, options) {
            this.bind('add', options.view.addOneWorld);
        }
    });
    var AppView = Backbone.View.extend({
        el: $('body'),
        initialize: function () {
            this.worlds = new Worlds(null, {view: this});
        },
        events: {
            "click #check": "checkIn"
        },
        checkIn: function () {
            var world_name = prompt("请问，您是哪里人？");
            if (!$.trim(world_name).length)
                world_name = "未知";
            this.worlds.add(new World({name: world_name}));
        },
        addOneWorld: function (model) {
            $('#world-list').append('<li>这是来自 <b>' + model.get('name') + '</b> 星球的问候：hello world!</li>');
        }
    });
    new AppView;
});